package com.modbus.service.impl;

import com.modbus.ModbusTcpUtil;
import com.modbus.eum.ModbusEnum;
import com.modbus.service.IModbusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.ExecutionException;
/**
 * @author heyayun
 */
@Slf4j
@Service("modbusService")
public class ModbusServiceImpl implements IModbusService {
    @Autowired
    private ModbusTcpUtil modbusTcpUtil;
    @Override
    public void get(int address, int unitId, ModbusEnum modbusEnum, int typeId) throws ExecutionException, InterruptedException {
        Number number;
        modbusTcpUtil.readCoils(address,typeId,unitId);
        /* switch (modbusEnum) {
            case COILS:
                Boolean coils = ModbusMasterTcp.readCoils(address, unitId, typeId);
                number = coils ? 1 : 0;
                break;
            case DISCRETE_INPUTS:
                Boolean discreteInputs = ModbusMasterTcp.readDiscreteInputs(address, unitId, typeId);
                number = discreteInputs ? 1 : 0;
                break;
            case HOLDING_REGISTERS:
                number = ModbusMasterTcp.readHoldingRegisters(address, unitId, typeId);
                break;
            case INPUT_REGISTERS:
                number = ModbusMasterTcp.readInputRegisters(address, unitId, typeId);
                break;
            default:
                number = -1;
        }
        log.info("address = " + address + " code = "
                + modbusEnum.getCode() + " unitId = " + unitId
                + " number = " + number.doubleValue() );
         */
    }
}
